package com.loong.seller.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.seller.common.backend.param.DeliveryWaysQueryParam;
import com.loong.seller.mapper.DeliveryWaysMapper;
import com.loong.seller.model.DeliveryWays;
import com.loong.seller.model.dto.DeliveryWaysDto;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-11-9 9:08
 */
@Component
public class DeliveryWaysBusiness extends AbstractBusiness<DeliveryWays> {
    @Resource
    DeliveryWaysMapper deliveryWaysMapper;

    /**
     * 分页查询
     * @param param
     * @return
     */
    public List<DeliveryWays> query(DeliveryWaysQueryParam param){
        Condition condition = new Condition(DeliveryWays.class);
        Example.Criteria criteria = condition.createCriteria();
        buildQueryCriteria(param,criteria);
        return findByCondition(condition);
    }
    //这里根据业务需求构造条件
    private void buildQueryCriteria(DeliveryWaysQueryParam param,Example.Criteria criteria){
        if(ObjectUtils.isNotEmpty(param.getName())){
            criteria.andEqualTo("name", param.getName());
            // criteria.andLike("name",param.getName());
        } if(ObjectUtils.isNotEmpty(param.getStatus())){
            criteria.andEqualTo("status",param.getStatus());
        }

    }

    public List<DeliveryWaysDto> findDetailByShopId(Long shopId) {
        return deliveryWaysMapper.findDetailByShopId(shopId);
    }


    public  List<DeliveryWaysDto> findDeliveryWaysByShopId(Long shopId) {
        return deliveryWaysMapper.findDeliveryWaysByShopId(shopId);
    }
}
